﻿Jxstar.currentPage = function() {
	var config = {param:{},initpage:function(page, define){},eventcfg:{}};
	
	var auditData = Jxstar.findComboData('audit');
	var items = [{
		height: '97%',
		width: '97%',
		border: false,
		layout: 'form',
		style: 'padding:10px;',
		items: [{
			anchor:'100%',
			border: false,
			layout:'column',
			autoHeight:true,
			items:[{
				border:false,
				columnWidth:0.495,
				layout:'form',
				style: 'padding-left:10px;',
				items:[
					{xtype:'trigger', fieldLabel:'合同编号', name:'project_designchg__contract_code',
						anchor:'100%', triggerClass:'x-form-search-trigger',
						maxLength:20, allowBlank:false, labelStyle:'color:#0000FF;', labelSeparator:'*', editable:false,
						onTriggerClick: function() {
							var selcfg = {pageType:'combogrid', nodeId:'contract_select', layoutPage:'', sourceField:';', targetField:';', whereSql:"contract_status  = '4'", whereValue:'', whereType:'', isSame:'1', isShowData:'1', isMoreSelect:'0',isReadonly:'1',fieldName:'project_designchg.contract_code'};
							JxSelect.createSelectWin(selcfg, this, 'node_project_designchg_form');
						}},
					{xtype:'textfield', fieldLabel:'合同名称', name:'project_designchg__contract_name', readOnly:true, anchor:'100%', maxLength:100},
					{xtype:'textfield', fieldLabel:'项目编码', name:'project_designchg__project_code', readOnly:true, anchor:'100%', maxLength:20},
					{xtype:'textfield', fieldLabel:'申请人', name:'project_designchg__apply_user', defaultval:'fun_getUserName()', readOnly:true, anchor:'100%', maxLength:20},
					{xtype:'datefield', fieldLabel:'申请日期', name:'project_designchg__apply_date', defaultval:'fun_getToday()', format:'Y-m-d', anchor:'100%', readOnly:true},
					{xtype:'textfield', fieldLabel:'施工单位', name:'project_designchg__provider_name', readOnly:true, anchor:'100%', maxLength:50},
					{xtype:'numberfield', decimalPrecision:2, fieldLabel:'累计变更金额(万元)', name:'project_designchg__money_allchg', readOnly:true, anchor:'100%', maxLength:12},
					{xtype:'hidden', fieldLabel:'项目ID', name:'project_designchg__project_id', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'主键', name:'project_designchg__designchg_id', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'申请人ID', name:'project_designchg__apply_userid', defaultval:'fun_getUserId()', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'施工监理ID', name:'project_designchg__super_userid', anchor:'100%'},
					{xtype:'trigger', fieldLabel:'项目负责人', name:'project_designchg__project_user',
						anchor:'100%', triggerClass:'x-form-search-trigger',
						maxLength:50, allowBlank:false, labelStyle:'color:#0000FF;', labelSeparator:'*', editable:false,
						onTriggerClick: function() {
							var selcfg = {pageType:'combogrid', nodeId:'sys_user', layoutPage:'/public/layout/layout_tree.js', sourceField:'sys_user.user_name;user_id', targetField:'project_designchg.project_user;project_userid', whereSql:"", whereValue:'', whereType:'', isSame:'0', isShowData:'1', isMoreSelect:'0',isReadonly:'1',fieldName:'project_designchg.project_user'};
							JxSelect.createSelectWin(selcfg, this, 'node_project_designchg_form');
						}}
				]
			},{
				border:false,
				columnWidth:0.495,
				layout:'form',
				style: 'padding-left:10px;',
				items:[
					{xtype:'combo', fieldLabel:'记录状态', name:'project_designchg__auditing', defaultval:'0',
						anchor:'100%', readOnly:true, editable:false,
						store: new Ext.data.SimpleStore({
							fields:['value','text'],
							data: auditData
						}),
						emptyText: jx.star.select,
						mode: 'local',
						triggerAction: 'all',
						valueField: 'value',
						displayField: 'text',
						value: auditData[0][0]},
					{xtype:'numberfield', decimalPrecision:2, fieldLabel:'合同金额(万元)', name:'project_designchg__contract_money', readOnly:true, anchor:'100%', maxLength:12},
					{xtype:'textfield', fieldLabel:'项目名称', name:'project_designchg__project_name', readOnly:true, anchor:'100%', maxLength:100},
					{xtype:'textfield', fieldLabel:'申请部门', name:'project_designchg__dept_name', readOnly:true, anchor:'100%', maxLength:50},
					{xtype:'datefield', fieldLabel:'实施日期', name:'project_designchg__practice_date', format:'Y-m-d', anchor:'100%'},
					{xtype:'textfield', fieldLabel:'施工位置', name:'project_designchg__constr_location', anchor:'100%', maxLength:50},
					{xtype:'numberfield', decimalPrecision:2, fieldLabel:'变更金额(万元)', name:'project_designchg__money_chg', allowBlank:false, labelStyle:'color:#0000FF;', labelSeparator:'*', anchor:'100%', maxLength:12},
					{xtype:'hidden', fieldLabel:'部门ID', name:'project_designchg__dept_id', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'施工单位ID', name:'project_designchg__provider_id', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'合同ID', name:'project_designchg__contract_id', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'项目负责人ID', name:'project_designchg__project_userid', anchor:'100%'},
					{xtype:'trigger', fieldLabel:'施工监理', name:'project_designchg__super_user',
						anchor:'100%', triggerClass:'x-form-search-trigger',
						maxLength:50, allowBlank:false, labelStyle:'color:#0000FF;', labelSeparator:'*', editable:false,
						onTriggerClick: function() {
							var selcfg = {pageType:'combogrid', nodeId:'sys_user', layoutPage:'/public/layout/layout_tree.js', sourceField:'sys_user.user_name;user_id', targetField:'project_designchg.super_user;super_userid', whereSql:"", whereValue:'', whereType:'', isSame:'0', isShowData:'1', isMoreSelect:'0',isReadonly:'1',fieldName:'project_designchg.super_user'};
							JxSelect.createSelectWin(selcfg, this, 'node_project_designchg_form');
						}}
				]
			}
			]
		},{
			anchor:'100%',
			border: false,
			layout:'column',
			autoHeight:true,
			items:[{
				border:false,
				columnWidth:0.99,
				layout:'form',
				style: 'padding-left:10px;',
				items:[
					{xtype:'textarea', fieldLabel:'变更内容', name:'project_designchg__constr_content', allowBlank:false, labelStyle:'color:#0000FF;', labelSeparator:'*', width:'100%', height:72, maxLength:200}
				]
			}
			]
		}]
	}];
	
	config.param = {
		items: items,
		funid: 'project_designchg'
	};

	config.initpage = function(formNode){
		var event = formNode.event;
		
		//扩展保存前事件，检查累计变更金额占合同比例
		event.on('beforesave', function(event, data) {
			var form = event.form;
			
			var money_chg = form.getNum('project_designchg__money_chg');
			var money_allchg = form.getNum('project_designchg__money_allchg');
			var contract_money = form.getNum('project_designchg__contract_money');
			if ( money_chg + money_allchg >= contract_money*0.1 ) {
				JxHint.alert('累计工程量变更金额已超过合同金额的10%！');
			}
			
			return true;
		});
	};
	
	return new Jxstar.FormNode(config);
}